package com.fgchen.controller;

import com.fgchen.biz.UserBiz;
import com.fgchen.domain.study01.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collection;

/**
 * Created by Administrator on 2018-04-08.
 */
@Controller
public class UserController {

    @Autowired
    private UserBiz userBiz;

    @RequestMapping("/user/insert")
    public String insert(String name, Integer age) {
        this.userBiz.insert(name, age);
        return "redirect:/users";
    }

    @ResponseBody
    @RequestMapping("/users")
    public Collection<User> users() {
        return this.userBiz.findAll();
    }

    @ResponseBody
    @RequestMapping("/user/{id}")
    public User user(@PathVariable("id") Long id) {
        return this.userBiz.get(id);
    }

}
